﻿namespace Collaboris.Saf.Actions.Entities
{
    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;

    
    using Engine;

    using SharePoint.Wss.Attributes;
    using SharePoint.Wss.Entities;

    [Serializable]
    [CollaborisClass(Title = "SQL Script", ReleaseStatus = ReleaseStatus.Stable, DisableDocumentation = false,
        ContactAuthorEmail = "Support@Collaboris.co.uk",
        Summary = "This class defines the settings to run a SQL script from SAF.")]
    public class SQLScript : EntityBase
    {
        #region Constants and Fields

        private List<string> arguments;

        private string connectionString;

        private string script;

        private string scriptFile;

        private int? timeout;

        #endregion

        #region Properties

        /// <summary>
        /// the url of the site to process the file upon
        /// </summary>
        public List<string> Arguments
        {
            get
            {
                return this.arguments;
            }
            set
            {
                this.arguments = value;
            }
        }

        [CollaborisProperty(Title = "Connection String", Summary = "Defines the information needed to connect to SQL server.",
            Required = true,
            Example = "Data Source=(local);Initial Catalog=msdb;Integrated Security=SSPI;")]
        public string ConnectionString
        {
            get
            {
                return this.connectionString;
            }
            set
            {
                this.connectionString = value;
            }
        }

        [CollaborisProperty(Title = "Script File", 
            Summary = "Defines path to a file containing SQL script to run.",
            Required = false, 
            Remarks = @"If both a 'ScriptFile' and 'ScripText' are supplied, both will be run. ScriptFile should be supplied like this 'C:\Temp\MyScript.SQL'")]
        public string ScriptFile
        {
            get
            {
                return this.scriptFile;
            }
            set
            {
                this.scriptFile = value;
            }
        }

        [CollaborisProperty(Title = "Script Text", Summary = "Defines Script Text to run against the SQL Server.",
            Required = false, 
            Example = "SELECT TOP 1 * from SysAlerts",
            Remarks = "If both a 'ScriptFile' and 'ScripText' are supplied, both will be run.")]
        public string ScriptText
        {
            get
            {
                return this.script;
            }

            set
            {
                this.script = value;
            }
        }

        [XmlElement(IsNullable = true)]
        [CollaborisProperty(Title = "Timeout",
            Summary = "Specifies the number of seconds to timeout the SQL command.", 
            Required = true,
            Remarks = "Defaults to 5000 if no value is supplied.", Example = "60")]
        public int? Timeout
        {
            get
            {
                return this.timeout;
            }
            set
            {
                this.timeout = value;
            }
        }

        #endregion
    }
}